package framework
{
	import flash.utils.getDefinitionByName;
	
	import mx.rpc.events.ResultEvent;
	import mx.rpc.http.HTTPService;
	
	public class XmlCtx
	{
		
		public var xmlFileName:String = "beans.xml";
		public var xmlCtxHttpService:HTTPService;
		public var c:Ctx;
		
		public function XmlCtx(xmlFileName:String = null)
		{
			if (xmlFileName)
			{
				this.xmlFileName = xmlFileName;
			}
		}
		public function initBean():void
		{
			handle(load(xmlFileName), configHandler);
		}

		private function configHandler(e:ResultEvent):void
		{
			var r:XML = e.result as XML;
			for each (var b:XML in r..bean)
			{
				var clz:Class = getDefinitionByName((b.attribute("class")[0])) as Class;
				var bean:Object = new clz;
				var id:String = b.@id;
				for each (var p:XML in b..property)
				{
					bean[p.@name] = p.value.toString();
				}
				c.addBean(bean,id);
			}
		}

	}
}